package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 访客计划 状态
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/1 11:32
 * @since v1.0
 */
@Getter
public enum CommunicatePlanStatusEnum {
    // 访客计划 状态
    NO_FOLLOW("1","noFollow", "enum.communicatePlanStatus.alias.no_follow"),
    FINISH("2","finish", "enum.communicatePlanStatus.alias.finish"),
    CANCEL("3","cancel", "enum.communicatePlanStatus.alias.cancel"),
    DELAY("4","delay", "enum.communicatePlanStatus.alias.delay"),

    UNKNOW("404","unkonw", "enum.communicatePlanStatus.alias.unknow")
    ;
    private String code;
    private String attr;
    private String alias;

    CommunicatePlanStatusEnum(String code, String attr, String alias) {
        this.code = code;
        this.attr = attr;
        this.alias = alias;
    }

    public static CommunicatePlanStatusEnum getByCode(String code){
        for (CommunicatePlanStatusEnum statusEnum : values()){
            if (Objects.equals(statusEnum.code,code)){
                return statusEnum;
            }
        }
        return UNKNOW;
    }

    public static List<CommunicatePlanStatusEnum> getList(){
        List<CommunicatePlanStatusEnum> enumList = new ArrayList<>();
        for (CommunicatePlanStatusEnum statusEnum : values()){
            if (Objects.equals(statusEnum,UNKNOW)){
                continue;
            }
            enumList.add(statusEnum);
        }
        return enumList;
    }

    public static CommunicatePlanStatusEnum getByAlias(String alias){
        for (CommunicatePlanStatusEnum statusEnum : values()){
            if (Objects.equals(statusEnum.getAlias(), alias)){
                return statusEnum;
            }
        }
        return null;
    }

    public String getAlias() {
        return I18nMessageUtil.getMessage(alias);
    }
}
